package com.currency.mall.ui.guide;

import android.app.Dialog;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.mifengs.commonbase.base.BaseActivity;
import com.mifengs.commonbase.util.PreferenceUtils;
import com.mifengs.commonbase.util.StatusBarCompat;
import com.mifengs.commonbase.util.Tools;
import com.currency.mall.R;
import com.currency.mall.ui.login.LoginActivity;
import com.currency.mall.ui.main.MainActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SplashActivity extends BaseActivity {

    private MyTime mMyTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //无title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        TinkerPatch.with().fetchPatchUpdate(true);
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        StatusBarCompat.setBottomBarTransluent(this);
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        int time = 1000;
        mMyTime = new MyTime(time, 1000);
        mMyTime.start();
    }


    class MyTime extends CountDownTimer {

        public MyTime(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {
        }

        @Override
        public void onFinish() {
            goToNextActivity();
        }
    }


    private void goToNextActivity() {
//        if (PreferenceUtils.getIsFirst(SplashActivity.this)) {
//            PreferenceUtils.saveIsFirst(SplashActivity.this, false);
//            Intent intent = new Intent(SplashActivity.this, GuideActivity.class);
//            startActivity(intent);
//            finish();
//        } else {
//            if("".equals(PreferenceUtils.getUid(getContext()))){
//                Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
//                startActivity(intent);
//            }else{
//                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
//                startActivity(intent);
//            }

//            finish();
//        }
        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }



    @Override
    protected void onDestroy() {
        if (mMyTime != null) {
            mMyTime.cancel();
        }
        super.onDestroy();
    }
}
